package com.zhouxiao.multithreading.countdownlatch;

import java.util.concurrent.CountDownLatch;

/**
 * CountDownLatch: 闭锁，在完成某些运输时，只有其他所有线程的运算全部完成，当前运算才继续执行
 */
public class CountDownLatchTest {
    public static void main(String[] args) {
        //此处5要和线程数一致
        final CountDownLatch latch = new CountDownLatch(5);
        LatchDemo latchDemo = new LatchDemo(latch);
        long start = System.currentTimeMillis();

        for (int i = 0; i < 5; i++) {
            new Thread(latchDemo).start();
        }
        try {
            latch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        long end = System.currentTimeMillis();
        System.out.println("耗费时间: " + (end - start));
    }
}
